package com.basement.dao;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.basement.model.BsmntUser;

public class UserDaoImpl extends HibernateDaoSupport implements UserDAO {
   

    public List<BsmntUser> readAll() {
        this.getSessionFactory().getCurrentSession().beginTransaction();
        List result = this.getSessionFactory().getCurrentSession().createQuery("from User").list();
        for (BsmntUser user : (List<BsmntUser>) result) {
            System.out.println("User (" + user.getName() + ") : "
                    + user.getLastName());
        }
        return result;
    }

    public BsmntUser readOne(Long id) {

        Criteria c = this.getSessionFactory().getCurrentSession().createCriteria(BsmntUser.class);
        c.add(Restrictions.idEq(id));
        //c.list();
        BsmntUser user = (BsmntUser) c.uniqueResult();
        System.out.println("User (" + user.getName() + ") : "
                + user.getLastName());
        return user;
    }

    public void save(BsmntUser user) {
        // TODO Auto-generated method stub
       
    }

    public void update(BsmntUser user) {
        // TODO Auto-generated method stub
       
    }

    public void delete(BsmntUser user) {
        // TODO Auto-generated method stub
       
    }

}